package com.lagou;

import com.lagou.bean.ConsumerComponent;
import com.lagou.filter.DubboInvokeFilter;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


public class AnnotationConsumerMain {
    static Logger logger = LoggerFactory.getLogger(AnnotationConsumerMain.class.getName());

    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);

        ExecutorService executorService = Executors.newFixedThreadPool(3);
        //for(int i=0;i<2;i++) {
            executorService.execute(() -> {
                while(true) {
                    service.methodA();
                }
            });
            executorService.execute(() -> {
                while(true) {
                    service.methodB();
                }
            });
            executorService.execute(() -> {
                while(true) {
                    service.methodC();
                }
            });
        //}
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.lagou.bean")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
